import Vue from 'vue'
import Vuex from 'vuex'
import user from './modules/user'
import setting from './modules/setting'
Vue.use(Vuex)
// 创建仓库
const store = new Vuex.Store({
  // 严格模式
  strict: true,
  state: {
    title: 'title',
    count: 100,
    list: [1, 2, 3, 4, 5, 4, 6, 7, 8, 9]
  },
  mutations: {
    // 所有mutation函数，第一个参数都是state
    addCount (state, n) {
      state.count += n
    },
    cTietl (state, obj) {
      state.title = obj.oldName
    },
    countSub (state, n) {
      state.count -= n
    },
    changeHandle (state, s) {
      state.count = s
    },
    cHandle (state, i) {
      state.title = i
    }
    /*     addCountt (state) {
      state.count += 5
    } */
  },
  actions: {
    changeHandleSluggish (context, num) {
      setTimeout(() => {
        context.commit('changeHandle', num)
      }, 1000)
    }
  },

  getters: {
    // 形参第一个参数是state
    // 必须有返回值，返回值是getters的值
    filterList (state) {
      return state.list.filter(item => item > 5)
    }
  },
  // modules 模块
  modules: {
    user,
    setting
  }
})

// 导出
export default store
